/**
 * 给定一个二叉树，返回所有从根节点到叶子节点的路径。
 * 
 * 输入:

   1
 /   \
2     3
 \
  5

输出: ["1->2->5", "1->3"]
 */



// dfs
/**
 * @param {TreeNode} root
 * @return {string[]}
 */
var binaryTreePaths = function (root) {
    let arr = []
    if (root === null) return arr
    let dfs = function (root, path) {
        if (root) {
            path += root.val
        }
        if (!root.left && !root.right) {
            arr.push(path)
            return
        } else {
            path += "->"
        }
        if (root.left) {
            dfs(root.left, path)
        }
        if (root.right) {
            dfs(root.right, path)
        }
    }
    dfs(root, "")
    return arr
};


// dfs
/**
 * @param {TreeNode} root
 * @return {number}
 */
var sumOfLeftLeaves = function (root) {
    let sum = 0
    const sum_recursion = (root) => {
        if(!root || !root.left && !root.right) {return}
        if(root.left && !root.left.left && !root.left.right) {
            sum += root.left.val
        }
        sum_recursion(root.left)
        sum_recursion(root.right)
    }
    sum_recursion(root)
    return sum
}